﻿
@{
    ViewBag.Title = "结算对账";
}
@section CSS{
    <style>
    </style>
}
<!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                结算中心
                <small></small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">财务管理</a></li>
                <li class="active">结算中心</li>
            </ol>
        </section>
        <section style="display:none;">
            <div class="col-xs-12">
                <div class="box box-primary ">
                    <!-- form start -->
                    <form class="form-horizontal">
                        <div class="box-body">
                            @*<div class="form-group">
                                <label for="status" class="col-sm-2 control-label">状态</label>
                                <div class="col-sm-2">
                                    <select class="form-control" id="status">
                                        <option value="-1">-请选择状态-</option>
                                        <option value="1">待结算</option>
                                        <option value="2">正在结算</option>
                                        <option value="4">退款待返款</option>
                                        <option value="5">已退款</option>
                                        <option value="6">货款结算成功</option>
                                    </select>
                                </div>
                                <label class="col-sm-2 control-label">订单编号</label>
                                <div class="col-sm-2">
                                    <input type="text" class="form-control" id="orderNo" placeholder="订单编号">
                                </div>
                            </div>
                            <div class="form-group" style="display:none;">
                                <label class="col-sm-2 control-label">结算日期</label>
                                <div class="col-sm-2">
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" class="form-control pull-right" id="startTime">
                                    </div>
                                </div>
                                <label style="float:left;"> - </label>

                                <div class="col-sm-2">
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" class="form-control pull-right" id="endTime">
                                    </div>
                                </div>
                            </div>*@
                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer ">
                            @*<button type="button" class="btn btn-primary btn-search center-block" id="btnSearch"><i class="fa fa-search"></i> 查询</button>*@
                            @*<button type="button" class="btn btn-danger" id="btnDelMul"><i class="fa fa-remove"></i> 批量删除</button>
                            <button type="button" class="btn btn-info" id="btnAdd"><i class="fa fa-plus"></i> 添加</button>
                            <button type="button" class="btn btn-success" id="btnExport"><i class="fa fa-download"></i> 导出Excel</button>*@
                        </div>
                        <!-- /.box-footer -->
                    </form>
                </div>
            </div>
        </section>
        <!-- Main content -->
        <section >
            <div class="col-xs-12 ">
                <div class="box box-primary" >
                    <div class="box-body" >
                        <div class="col-md-6">
                            <div class="info-box-content">
                                <span class="info-box-number"><small>订单货款总额 ￥</small><b style="font-size:30px;">@((Model == null ? 0 : Model.balance_settlement+ViewBag.Settlementing).ToString("f2"))</b> <small>元</small></span>
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div  style="text-align:center;">
                                <span class="info-box-number">￥<b>@(Model == null ? 0 : Model.balance_settlement.ToString("f2"))</b> <small>元</small></span>
                                <span class="info-box-text" style="color:#c2c1c1;">已结算订单</span>
                            </div>
                        </div>
                        <div class="col-md-3" >
                            <div style="border-left:1px #cdcdcd solid;text-align:center;">
                                <span class="info-box-number">￥<b>@ViewBag.Settlementing.ToString("f2")</b> <small>元</small></span>
                                <span class="info-box-text" style="color:#c2c1c1;">待结算订单</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <section class="content">
            
            @*<div class="row">
                <div class="col-md-6 col-sm-6 col-xs-12">
                    <div class="info-box">
                        <span class="info-box-icon bg-green "><i class="ion ion-social-yen-outline"></i></span>

                        <div class="info-box-content">
                            <span class="info-box-text">销售总额</span>
                            <span class="info-box-number">￥@(Model == null ? 0 : (Model.balances + Model.balance_freeze).ToString("f2"))<small>元</small></span>
                        </div>
                        <!-- /.info-box-content -->
                    </div>
                    <!-- /.info-box -->
                </div>
                <!-- /.col -->
                <!-- /.col -->
                <!-- fix for small devices only -->
                <div class="clearfix visible-sm-block"></div>
                <div class="col-md-3 col-sm-6 col-xs-12">
                    <div class="info-box">
                        <span class="info-box-icon bg-aqua"><i class="ion ion-social-buffer-outline"></i></span>

                        <div class="info-box-content">
                            <span class="info-box-text">已结算</span>
                            <span class="info-box-number">￥@(Model == null ? 0 : Model.balance_freeze.ToString("f2"))<small>元</small></span>
                        </div>
                        <!-- /.info-box-content -->
                    </div>
                    <!-- /.info-box -->
                </div>
                <div class="col-md-3 col-sm-6 col-xs-12">
                    <div class="info-box">
                        <span class="info-box-icon bg-yellow"><i class="fa ion-ios-timer-outline "></i></span>

                        <div class="info-box-content">
                            <span class="info-box-text">待结算</span>
                            <span class="info-box-number">￥@(Model == null ? 0 : Model.balance_due.ToString("f2"))<small>元</small></span>
                        </div>
                        <!-- /.info-box-content -->
                    </div>
                    <!-- /.info-box -->
                </div>

            </div>*@
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header my_search">
                            <select style="width:150px;" class="form-control" id="status">
                                <option value="-1">- 结算状态 -</option>
                                <option value="1">待结算</option>
                                <option value="2">正在结算</option>
                                <option value="4">退款待返款</option>
                                <option value="5">已退款</option>
                                <option value="6">货款结算成功</option>
                            </select>
                            <input type="text" style="width:120px;" class="form-control pull-left" id="startTime" placeholder="结算日期-起">
                            <span style="line-height:30px;">至</span>
                            <input type="text" style="width:120px; " class="form-control pull-left" id="endTime" placeholder="结算日期-止">
                            <input type="text" style="width:180px;" class="form-control" id="orderNo" placeholder="订单编号">
                            <button type="button" class="btn btn-default " id="btnSearch"><i class="fa fa-search"></i> 搜索</button>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body">
                            <table id="DataList" class="table table-bordered table-striped table-hover ">
                                <thead>
                                    <tr>
                                        @*<th>交易时间</th>
                                    <th>流水编号</th>*@
                                        <th>订单编号</th>
                                        <th>订单金额</th>
                                        <th>费率</th>
                                        <th>服务费</th>
                                        <th>结算金额</th>
                                        <th>发货时间</th>
                                        <th>账期</th>
                                        <th>结算日期</th>
                                        <th>状态</th>
                                        @*<th width="200">备注</th>*@
                                        <th>查看</th>
                                    </tr>
                                </thead>
                                <tbody> </tbody>
                            </table>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
<!-- /.content-wrapper -->
@section JS{
    <script>
        $(function () {
            //初始化表格
            GenerateTable();
            //鼠标移动到该行变色
            $('.table-hover tbody').on('click', 'tr', function () {
                if ($(this).hasClass('selected')) {
                    $(this).removeClass('selected');
                }
                else {
                    u_table.$('tr.selected').removeClass('selected');
                    $(this).addClass('selected');
                }
            });
            //搜索事件
            $("#btnSearch").on("click", function () {
                var classSelect = $("#classSelect").val();
                var datemin = $('#startTime').val();
                var datemax = $("#endTime").val();
                if ((datemin == null && datemax != null) || (datemin != null && datemax == null)) {
                    layer.msg('请把时间填充完整!', { icon: 1, time: 1000 });
                }
                else {
                    u_table.fnDestroy();
                    GenerateTable();
                }
            });

            $('#startTime').datepicker({
                autoclose: true
            });

            $('#endTime').datepicker({
                autoclose: true
            });
        });
        //生成表格
        function GenerateTable() {
            u_table = $('#DataList').dataTable({
                "lengthChange": false,
                "searching": false,
                "ordering": false,
                "iDisplayLength": 15,
                "bProcessing": true,
                "bServerSide": true,
                "fnServerParams": function (aoData) {
                    var status = $("#status").val();
                    var orderNo = $("#orderNo").val();
                    var datemin = $('#startTime').val();
                    var datemax = $("#endTime").val();
                    aoData.push(
                        { "name": "dateMin", "value": datemin },
                        { "name": "dateMax", "value": datemax },
                        { "name": "orderNo", "value": orderNo },
                        { "name": "status", "value": status }
                    );
                },
                "sAjaxSource": "/finance/FinanceCheckList",
                "aoColumns": [
                    //{
                    //    "mDataProp": 'add_time', "mRender": function (data, type, full) {
                    //        return moment(data).format("YYYY-MM-DD HH:mm:ss");
                    //    }
                    //},
                    //{ "mDataProp": 'id' },
                    //{ "mDataProp": 'settlement_no' },
                     {
                         "mDataProp": 'order_no', "mRender": function (data, type, full) {
                             return ' <a href = "/Order/GoodsOrder/' + full.order_id + '" target="_blank"  title="订单详情">'+data+'</a> ';
                         }
                     }
                    ,{
                        "mDataProp": 'order_total', "mRender": function (data, type, full) {
                            return "￥"+data;
                        }
                    },
                     {
                         "mDataProp": 'service_rate', "mRender": function (data, type, full) {
                             return data>0?(data + "%"):"-";
                         }
                     },
                    {
                        "mDataProp": 'service_rate', "mRender": function (data, type, full) {
                            //return "￥"+((data / 100) * full.order_total).toFixed(2);
                            //return data>0?(full.order_total-full.money).toFixed(2):"-";
                            return (full.order_total-full.money).toFixed(2);
                        }
                    },
                    {
                        "mDataProp": 'money', "mRender": function (data, type, full) {
                            //return "￥" + (data - (full.service_rate / 100) * data).toFixed(2);
                            return "￥" +data;
                        }
                    }
                    ,{
                        "mDataProp": 'add_time', "mRender": function (data, type, full) {
                            return moment(data).format("YYYY-MM-DD")+"<br/>&nbsp;&nbsp;"+moment(data).format("HH:mm:ss");
                        }
                    }
                     ,{
                         "mDataProp": 'account_period', "mRender": function (data, type, full) {
                             return "T+"+data;
                         }
                     }
                     ,{
                         "mDataProp": 'settlement_time', "mRender": function (data, type, full) {
                             return data==null||data==""?"-":moment(data).format("YYYY-MM-DD");
                        }
                    }
                    //{ "mDataProp": 'money' },
                   ,{
                       "mDataProp": 'status', "mRender": function (data, type, full) {
                           return data == 1 ? "<span style='color:#333'>待结算</span>" : (data == 6 ? "<span style='color:gray'>结算成功</span>" : (data == 2 ? "<span style='color:orange'>正在结算</span>" : (data == 4 ? "<span style='color:#333'>待退款</span>" : (data == 5 ? "<span style='color:gray'>已退款</span>" : "<span style='color:red'>异常</span>"))));
                           //return data == 1 ? "<span style='color:orange'>待结算</span>" : (data == 6 ? "<span style='color:green'>结算成功</span>" : (data == 2 ? "<span style='color:blue'>正在结算</span>" : (data == 4 ? "<span style='color:orange'>待退款</span>" : (data == 5 ? "<span style='color:green'>已退款</span>" : "<span style='color:red'>异常</span>"))));
                           //return data == 1 ? "待结算" : (data == 6 ? "结算成功" : (data == 2 ? "正在结算" : (data == 4 ? "待退款" : (data == 5 ? "已退款" : "异常"))));
                        }
                    }
                    //,{ "mDataProp": 'remark' }
                    , {
                        "mDataProp": 'id', "mRender": function (data, type, full) {
                            //return ' <a href = "/Order/GoodsOrder/' + full.order_id + '" target="_blank"  title="详情">订单详情</a> ';
                            return ' <a href="javascript:void(0);" onclick="admin_edit(\'详情\',\'/Finance/FinanceCheckDetails\',' + full.id + ',900,600)"  title="详情">详情</a> ';
                        }
                    }
                ]
            });
        }

        /*编辑*/
        function admin_edit(title, url, id, w, h) {
            layer_show(title, url, id, w, h);
        };
    </script>
}
